<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        KFC71AE86R7DSN
        yuanshen
        NTWQ4ZGDNC7N
        5TXRMZHU6V9S
        DBF9MHHU7U8E
    </div>

    <script src="../src/react.js"></script>
    <script src="../src/react-dom.js"></script>
    <script src="../src/babel.js"></script>

    <style>
        .active {
            color: red;
        }
    </style>

    <script type="text/babel">
        function Onec(){
            return <div>选项一 的内容</div>
        }

        class Tab extends React.Component {
            constructor() {
                super();
                this.state = {
                    flag: 1,
                    twoc:  <Onec></Onec>
                }
            }

            changeTab = (n) => {
                this.setState({
                    flag: n
                })

                switch (n) {
                    case 1:
                        this.setState({
                            twoc: <div>选项一 的内容</div>
                        })

                        break;
                    case 2:
                        this.setState({
                            twoc: <div>选项二 的内容</div>
                        })
                        break;
                    case 3:
                        this.setState({
                            twoc: <div>选项三 的内容</div>
                        })
                        break;
                    default:
                        this.setState({
                            twoc: <div>选项一 的内容</div>
                        })
                        break;
                }
            }

            render() {
                return (
                    <div>
                        <div>
                            <p className={this.state.flag == 1 ? 'active' : ''}
                                onClick={() => this.changeTab(1)}
                            >选项一</p>
                            <p className={this.state.flag == 2 ? 'active' : ''}
                                onClick={() => this.changeTab(2)}
                            >选项二</p>
                            <p className={this.state.flag == 3 ? 'active' : ''}
                                onClick={() => this.changeTab(3)}
                            >选项三</p>
                        </div>

                        <div>
                            {this.state.twoc}
                        </div>
                    </div>
                )
            }
        }
        let element = (
            <div>
                <Tab></Tab>
            </div>
        )

        ReactDOM.render(
            element,
            document.getElementById("app")
        )


    </script>
</body>

</html>